import 'dart:developer';

import 'package:flutterlib/common/net/api.dart';
import 'package:flutterlib/common/net/retrofit/activity_api.dart';
import 'package:flutterlib/common/net/retrofit/post_api.dart';
import 'package:flutterlib/model/activity/activity.dart';
import 'package:flutterlib/model/activity/activity_detail_bean.dart';
import 'package:flutterlib/model/interest/interest_bean.dart';
import 'package:flutterlib/model/post/comment_bean_tree.dart';
import 'package:logger/logger.dart';
import 'package:mobx/mobx.dart';
part 'activity_store.g.dart';

class ActivityStore = _ActivityStore with _$ActivityStore;

abstract class _ActivityStore with Store {

  @observable
  ObservableFuture<ActivityDetailBean> activityFuture;

  @action
  Future fetchActivity(int id) => activityFuture =
      ObservableFuture(ActivityApi(HttpManager().getDio()).getActivity(id));


  List<Activity> myActivitys = [];

  static ObservableFuture<List<Activity>> emptyResponse =
      ObservableFuture.value([]);

  @observable
  ObservableFuture<List<Activity>> myActivitysFuture = emptyResponse;

  @observable
  ObservableFuture<List<Activity>> myApplyActivitysFuture = emptyResponse;

  @action
  Future fetchMyActivity(int userId) =>
    myActivitysFuture=
      ObservableFuture(ActivityApi(HttpManager().getDio()).getActivitys(userId));

  @action
  Future fetchMyApplyActivity(int userId) =>
    myApplyActivitysFuture=
        ObservableFuture(ActivityApi(HttpManager().getDio()).getApplyActivitys(userId));

  @computed
  bool get hasResults =>
      myActivitysFuture != emptyResponse &&
      myActivitysFuture.status == FutureStatus.fulfilled;

  @computed
  List<Activity> get pendingActivitys{
    log("xxx");
    if(hasResults){

      List<Activity> activitys = myActivitysFuture.result;
      var list = activitys.where((element) => element.status != 2).toList();
      return list;
    }
     return [];
  }



  @computed
  List<Activity> get endActivitys{
    log("xxx");
    if(hasResults){

      List<Activity> activitys = myActivitysFuture.result;
      var list = activitys.where((element) => element.status == 2).toList();
      return list;
    }
    return [];
  }

  @observable
  ObservableFuture<CommentBeanTree> activityCommentFuture;

  @action
  Future fetchActivityComment(int id, int page, String order) => activityCommentFuture =
      ObservableFuture(PostApi(HttpManager().getDio()).commentPageByQuery(id, page, order));


}
